#pragma once

#include "QGlobalShortcut.h"
#include <QAbstractEventDispatcher>
#include <QKeySequence>
#include <QHash>

namespace kryptos { namespace util {

class QGlobalShortcutPrivate
{
public:

    QGlobalShortcutPrivate(QGlobalShortcut &handler);
    virtual ~QGlobalShortcutPrivate();

    QGlobalShortcut &handler;
    bool enabled;
    Qt::Key key;
    Qt::KeyboardModifiers mods;

    bool setShortcut(const QKeySequence& shortcut);
    bool unsetShortcut();

    static bool error;

#ifndef Q_WS_MAC
    static int ref;
    static QAbstractEventDispatcher::EventFilter prevEventFilter;
    static bool eventFilter(void* message);
#endif // Q_WS_MAC

    static void activateShortcut(quint32 nativeKey, quint32 nativeMods);

private:
    static quint32 nativeKeycode(Qt::Key keycode);
    static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers);

    static bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
    static bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);

    static QHash<QPair<quint32, quint32>, QGlobalShortcut*> shortcuts;
};

}}
